<template>
  <div>
    <el-table
        :data="tableData"
        style="width: 100%"
        :default-sort="{prop: 'date', order: 'descending'}"
    >
      <el-table-column type="index" header-align="center" align="center" label="编号"></el-table-column>

      <el-table-column prop="realName" sortable label="申述人" header-align="center" align="center"
                       width="180"></el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="申述时间"></el-table-column>
      <el-table-column prop="connect" header-align="center" align="center" label="申述内容"></el-table-column>
      <el-table-column label="操作" header-align="center" align="center">
        <template slot-scope="scope">
          <el-button size="small" style="background-color: #0096dc" @click="open(scope.row)">修改</el-button>
          <el-button size="small" style="background-color: #0096dc" @click="openDeleteConfirm(scope.row)">撤销</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="申诉信息" :visible.sync="dialogFormVisible">
      <el-form :model="allega" :rules="rules1" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="您的姓名" prop="realName">
          <el-input v-model="allega.realName"></el-input>
        </el-form-item>
        <el-form-item label="车位编号" prop="locationNumber">
          <el-input v-model="allega.locationNumber"></el-input>
        </el-form-item>
        <el-form-item label="对方车牌号" prop="carId">
          <el-input v-model="allega.carId"></el-input>
        </el-form-item>
        <el-form-item label="申诉内容" prop="connect">
          <el-input type="textarea" v-model="allega.connect"></el-input>
        </el-form-item>
        <el-form-item style="position: relative;right: 45px;">
          <el-button @click="update()">修改</el-button>
        </el-form-item>

      </el-form>
    </el-dialog>
  </div>
</template>

<script>


export default {
  data() {
    return {
      tableData: [],
      dialogFormVisible:false,
      allega: {}
    }
  },
  methods: {
    update(){
      let url ='http://localhost:8080/allega/update'
      console.log(this.allega)
      this.axios.post(url,this.allega).then((response)=>{
        let responseBody = response.data
        if (responseBody.code==200){
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          });
          this.loadAllega()
          this.dialogFormVisible=false
        }else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
          this.loadAllega()
        }
      });
    },
    open(row) {
      let url = 'http://localhost:8080/allega/userGetAllage?id=' + row.id
      console.log(url)
      this.axios.get(url).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          console.log(responseBody.data)
          this.allega = responseBody.data
          this.dialogFormVisible=true
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    },
    openDeleteConfirm(row) {
      this.$confirm('是否撤销该申诉, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.del(row)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消撤销'
        });
      });
    },
    del(row) {
      console.log(row.id)
      let url = 'http://localhost:8080/allega/delete?id=' + row.id
      this.axios.post(url).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          this.$message({
            showClose: true,
            message: '撤销成功',
            type: 'success'
          });
          this.loadAllega()
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
          this.loadAllega()
        }
      });

    },
    get() {
      let url = 'http://localhost/allega/getAllage'
      this.axios.get(url).then((response) => {
        let responseBody = response.data
      });
    },
    loadAllega() {
      let url = 'http://localhost:8080/allega/loadAllega?cardId='+localStorage.getItem('cardId')
      this.axios.get(url).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          this.tableData = responseBody.data;
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });

    },
  },
  created() {
    this.loadAllega();
  }
}
</script>

